package com.luchao.springcloudconsumerdept9001;

import com.luchao.springcloudapi.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class DeptConsumerController {

    @Autowired
    private RestTemplate restTemplate;
    private static final String URL_PREFIX = "http://localhost:8001";

    @RequestMapping("/consumer/dept/add")
    public boolean add(Dept dept) {
        return restTemplate.postForObject(URL_PREFIX + "/dept/add", dept, boolean.class);
    }

    @RequestMapping("/consumer/dept/getById/{id}")
    public Dept getById(@PathVariable("id") Long id) {
        return restTemplate.getForObject(URL_PREFIX + "/dept/getById/" + id, Dept.class);
    }

    @RequestMapping("/consumer/dept/getList")
    public List<Dept> getList() {
        return restTemplate.getForObject(URL_PREFIX + "/dept/getList", List.class);
    }

    @RequestMapping("/consumer/dept/discovery")
    public Object discovery() {
        return restTemplate.getForObject(URL_PREFIX+"/discovery",Object.class);
    }

}
